<template>
  <div id="shareTopSearch">
    <h1 class="con-right-title">
      集赞图审核
    </h1>
    <div class="search-box">
      <el-form
        ref="formInline"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="活动名称">
          <el-select
            v-model="formInline.activityId"
            filterable
            placeholder="请选择"
          >
            <el-option
              v-for="item in activeList"
              :key="item.id"
              :label="item.activityName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 输入搜索部分 -->
        <el-form-item label="大鹏号" prop="dpAccount">
          <el-input
            clearable
            v-model="formInline.dpAccount"
            placeholder="请输入大鹏号"
            size="small"
            class="numberInput"
          ></el-input>
        </el-form-item>
        <el-form-item label="集赞数" prop="sort">
          <el-select v-model="formInline.sort" clearable filterable>
            <el-option
              v-for="item in praiseList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核结果" prop="auditingState">
          <el-select v-model="formInline.auditingState" clearable filterable>
            <el-option
              v-for="item in auditingStateList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间查询" prop="timeType">
          <el-select v-model="formInline.timeType" clearable filterable>
            <el-option
              v-for="item in timeTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="useTime">
          <el-date-picker
            v-model="formInline.useTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('formInline')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'shareTopSearch',
  msg: '集赞图审核-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          activityId: '', //活动id
          activityName: '', //活动名称
          dpAccount: '', // 大鹏号
          sort: '', // 集赞数排序  从高到低  从低到高
          startTime: '', // 上传作品或上传截图开始时间
          endTime: '', // 上传作品或上传截图结束时间
          timeType: '', //上传时间类型
          useTime: [], // 使用时间
          auditingState: ''
        }
      }
    },
    activeList: {
      type: Array
    }
  },
  data() {
    return {
      rules: {},
      auditingStateList: [
        { dictLabel: '通过', dictValue: 'PASS' },
        { dictLabel: '未通过', dictValue: 'FAIL' },
        { dictLabel: '未审核', dictValue: 'UNAUDITED' }
      ],
      // 集赞数列表排序方式
      praiseList: [],
      //集赞时间类型
      timeTypeList: []
    }
  },
  watch: {
    'formInline.timeType': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.useTime = []
        }
      },
      deep: true
    },
    'formInline.useTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    async getStatusList() {
      /*集赞时间类型*/
      let timedata = await sysNormalDisable(
        'collections_time_type',
        'collections_time_type'
      )
      this.timeTypeList = this.timeTypeList.concat(timedata)
      this.formInline.timeType = this.timeTypeList[1].dictValue

      /*集赞数排序类型*/
      let sortdData = await sysNormalDisable(
        'collections_praise_type',
        'collections_praise_type'
      )
      this.praiseList = this.praiseList.concat(sortdData)
      this.formInline.sort = this.praiseList[1].dictValue
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['formInline'].resetFields()
      this.formInline.timeType = this.timeTypeList[1].dictValue
      this.formInline.sort = this.praiseList[1].dictValue
    }
  }
}
</script>
